home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / langguid / chap_04 / xmpl_04.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.9 KB  |  61 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Kaleida Labs, Inc.
  3. -- Field Guide to the ScriptX Language
  4. -- chapter 4, example 4
  5.  
  6. -- for loop examples with collect or select
  7.  
  8. -- create a module to be sure that names used here do not
  9. -- conflict with names used previously
  10. module Scratch16 uses ScriptX end
  11. in module Scratch16
  12.  
  13. -- declare globals
  14. global firstArray, secondArray, thirdArray, bigJumbledArray, \
  15.     niceNeatArray, sinvals, negativesins, status, i, squares, s, \
  16.     nums, doors, openDoors, reagan, speech
  17.  
  18. for i := 1 to 10 collect i
  19. global sinvals := for i := 1 to 3 collect sin i
  20. global negativesins := for i := 1 to 10 select (sin i) if (sin i) < 0
  21.  
  22. global status := #(@doorClosed:false, @keyInIgnition:true, 
  23.         @propellerMoving:true)
  24. print status
  25.  
  26. for i in #(@doorClosed, @keyInIgnition, @propellerMoving) 
  27.     select i if status[i] = true
  28.  
  29. global squares := #()
  30. for s in 1 to 10 collect into squares (s * s)
  31.  
  32. nums := for i in 1 to 5 collect i
  33. for i in 20 to 23 collect into nums i
  34. for i in 40 to 45 collect into nums i
  35.  
  36. global doors, openDoors := #()
  37. doors := #(@front:false,@back:true,@side:true,@garage:false)
  38. for i in #(@front,@back,@side,@garage)
  39. select i into openDoors if doors[i] = true
  40.  
  41. global firstArray := #(1,2,3,4,5)
  42. global secondArray := #(@yes,@no,@maybe)
  43. global thirdArray := #("sow","ewe","cow","hen")
  44. bigJumbledArray := #(firstArray,secondArray,thirdArray)
  45. niceNeatArray := #()
  46. for i in bigJumbledArray collect into niceNeatArray by merge i
  47.  
  48. global reagan := new String string:""
  49. speech := "Facts are stupid things"
  50. -- define a function that can act as a collector or selector
  51. function prependReturningSelf sequence value -> (
  52.     prepend sequence value
  53.     return sequence
  54. )
  55. -- use the collector function to reverse the string
  56. for i in speech collect into reagan by prependReturningSelf i
  57.  
  58. -- as clause in a for loop
  59. for i in "jabberwocky" collect as Array i
  60. for i in "jabberwocky" select i as String if i > 105
  61. -->>>